package com.simoniu.scalademo

import org.apache.spark.{SparkConf, SparkContext}

object CreateRddByArrayScalaDemo {
  def main(args: Array[String]): Unit = {
    //创建SparkContext
    val conf = new SparkConf()
    conf.setAppName("CreateRddByArrayScala ")//设置任务名称
      .setMaster("local")//local表示在本地执行
    val sc = new SparkContext(conf)
    //创建集合
    val arr = Array(1,2,3,4,5)
    //基于集合创建RDD
    val rdd = sc.parallelize(arr)
    val sum = rdd.reduce(_ + _)
    println(sum)
    //停止SparkContext
    sc.stop()
  }
}
